Microsoft Agent and Visual Basic .Net development

Making a character recognize a user’s speech input

 

5.1              Adding commands to a character

Commands are the words or sentences that the user speaks through the microphone, but, the character will not recognize any command given by the user unless you program a command into it. To add a command to your character, add this to your code:

 

    Character.Commands.Add("LetsGoForLunch.", , "LetsGoForLunch.", _

                          True, False)

 

This adds the command “LetsGoForLunch” to your character.  The first time “LetsGoForLunch” is written, that is the command Name, the command name is how the character hears the commands. The next time “LetsGoForLunch” is written, that is the command Voice, that is what the Listening tip will show; like if the command name was “KillItAllNow” and the command voice was “KillIt”, then the listening tip would display, “Character heard KillIt.”

 

5.2              Making a character respond to a command

To make a character respond to the “LetsGoForLunch” command, add this to your code:

 

    Private Sub agtAgent_Command(ByVal sender As Object, _

        ByVal e As AxAgentObjects._AgentEvents_CommandEvent)_

        Handles agtAgent.Command

 

        Dim command As AgentObjects.IAgentCtlUserInput = _

            CType(e.userInput, AgentObjects.IAgentCtlUserInput)

 

        If command.Name = "LetsGoForLunch" Then

            Character.Speak("No thanks, I’m not hungry.")

        End If

    End Sub

 

This code is in the agtAgent_Command sub.  The If/Then statement says, if the command name is “LetsGoForLunch” then the character will say, “No thanks, I’m not hungry.”

 

5.3              Making it easier

To make programming commands easier, you can add brackets ([ ]), stars (*), addition signs (+), and vertical bars (|) into the command Name.

 

You use the star to specify zero or more instances of the word, like this: "Don’t* kill me!"

Don’t can be said zero or more times and the character will still recognize it as “Don’t kill me!”

 

You use the vertical bar to let the character know that the word can be said different ways or that it can be said multiple times, like this: "Sayev|Save".  People with a accent might say “Sayev”, while others would say “Save”.  You would do it like this so that something could be said multiple times:

"call (one|two|three|four|five|six|seven|eight|nine|zero)",

This way the person can say “call 123-455-9321”.

 

You can use the plus sign the same way you use the star, except with the plus sign its one or more instances of the word.

 

You can use brackets to tell the character that a person can say a word, but they don’t have to, like this: "(hello [there] | hi)", this means that the person doesn’t have to say “there”, and they can say a combination of “hello there”, or “hi there”, or “hello”, and so on.